package com.bigcms.config;

import com.bigcms.interceptor.CorsInterceptor;
import com.bigcms.interceptor.Loginceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class InterceptorConfig implements WebMvcConfigurer{
    @Bean
    CorsInterceptor corsInterceptor(){return new CorsInterceptor();}

    @Bean
    Loginceptor loginceptor(){return new Loginceptor();}

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //跨域解决
        registry.addInterceptor(corsInterceptor()).addPathPatterns("/**");
        //用户鉴权
        registry.addInterceptor(loginceptor()).addPathPatterns("/api/v1/**")
                //不拦截的路由
                .excludePathPatterns("/api/v1/pub/**") ;
    }
}
